package com.yc.framework.baseClass;

import java.util.HashMap;

/**
 * 统一返回给前端的数据类型
 */
public class R extends HashMap<String, Object> {
    private R() {
        put("code", 201);
        put("success", true);
        put("message", "操作成功");
    }

    public static R ok() {
        return ok("操作成功");
    }
    public static R ok(String msg) {
        R r= new R();
        r.put("message",msg);
        return r;
    }

    public static R err() {
        return err("操作失败");
    }
    public static R err(String msg) {
        return err(501,msg);
    }
    public static R err(int code,String msg) {
        R r = new R();
        r.put("code", code);
        r.put("success", false);
        r.put("message", msg);
        return r;
    }

    public R put(String key, Object value) {
        super.put(key, value);
        return this;
    }
}
